package com.origin.app.utils

import com.origin.app.MyApplication
import com.origin.app.bean.UserInfoBean
import com.origin.utils.SharedPreferencesUtils
import com.origin.utils.gson.GsonUtils
import com.origin.utils.gson.GsonUtils.strToJavaBean
import com.origin.utils.gson.GsonUtils.toJsonString
import com.origin.utils.log.LogUtils

object UserInfoUtils {
    private var _userInfo: UserInfoBean = UserInfoBean();
    fun   isLogin():Boolean{
        try {
            getUserInfo()
            return (_userInfo.id!=null&&_userInfo.id!=0);
        }catch (e:Exception){
            return  false;
        }

    }
    fun getUserInfo(): UserInfoBean {
        if(_userInfo.id==null||_userInfo.id==0){
            try {
                var strInfo= SharedPreferencesUtils.getParam(
                    MyApplication.getInstance(),
                    "userInfo",
                    ""
                ) as String
                _userInfo =    strInfo.strToJavaBean(UserInfoBean::class.java)
            }catch (e:Exception){

            }
        }

        return _userInfo;
    };
    fun saveUserInfo(userInfo: UserInfoBean) {
        _userInfo = userInfo;
        SharedPreferencesUtils.setParam(
            MyApplication.getInstance(),
            "userInfo",
            userInfo.toJsonString()
        )
    }
}